package com.ruoyi.web.controller.blog;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.blog.domain.BizArticleTags;
import com.ruoyi.blog.service.IBizArticleTagsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文章标签Controller
 * 
 * @author wsa
 * @date 2019-10-20
 */
@Controller
@RequestMapping("/blog/articletags")
public class BizArticleTagsController extends BaseController
{
    private String prefix = "blog/articletags";

    @Autowired
    private IBizArticleTagsService bizArticleTagsService;

    @RequiresPermissions("blog:articletags:view")
    @GetMapping()
    public String articletags()
    {
        return prefix + "/articletags";
    }

    /**
     * 查询文章标签列表
     */
    @RequiresPermissions("blog:articletags:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BizArticleTags bizArticleTags)
    {
        startPage();
        List<BizArticleTags> list = bizArticleTagsService.selectBizArticleTagsList(bizArticleTags);
        return getDataTable(list);
    }

    /**
     * 导出文章标签列表
     */
    @RequiresPermissions("blog:articletags:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BizArticleTags bizArticleTags)
    {
        List<BizArticleTags> list = bizArticleTagsService.selectBizArticleTagsList(bizArticleTags);
        ExcelUtil<BizArticleTags> util = new ExcelUtil<BizArticleTags>(BizArticleTags.class);
        return util.exportExcel(list, "articletags");
    }

    /**
     * 新增文章标签
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文章标签
     */
    @RequiresPermissions("blog:articletags:add")
    @Log(title = "文章标签", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BizArticleTags bizArticleTags)
    {
        return toAjax(bizArticleTagsService.insertBizArticleTags(bizArticleTags));
    }

    /**
     * 修改文章标签
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BizArticleTags bizArticleTags = bizArticleTagsService.selectBizArticleTagsById(id);
        mmap.put("bizArticleTags", bizArticleTags);
        return prefix + "/edit";
    }

    /**
     * 修改保存文章标签
     */
    @RequiresPermissions("blog:articletags:edit")
    @Log(title = "文章标签", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BizArticleTags bizArticleTags)
    {
        return toAjax(bizArticleTagsService.updateBizArticleTags(bizArticleTags));
    }

    /**
     * 删除文章标签
     */
    @RequiresPermissions("blog:articletags:remove")
    @Log(title = "文章标签", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(bizArticleTagsService.deleteBizArticleTagsByIds(ids));
    }
}
